package com.learning.dynamic.executor.executor;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.*;

/**
 * @author Wang Xu
 * @date 2023/11/7
 */
public class DynamicExecutor extends ThreadPoolExecutor {

    private String poolName;

    public DynamicExecutor(int corePoolSize, int maximumPoolSize, String poolName) {
        this(corePoolSize, maximumPoolSize, new ThreadFactoryBuilder()
                .setNameFormat(poolName + "-worker-%d")
                .setDaemon(true).build());
        this.poolName = poolName;
    }

    public DynamicExecutor(int corePoolSize, int maximumPoolSize, ThreadFactory factory) {
        super(corePoolSize, maximumPoolSize, 0, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), factory);
    }

    public String getPoolName() {
        return poolName;
    }

    public void setPoolName(String poolName) {
        this.poolName = poolName;
    }
}